package com.net.wanjian.networkhospitalmanager.activity.skilltrain;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.activity.PhotoViewActivity;
import com.net.wanjian.networkhospitalmanager.activity.base.BaseActivity;
import com.net.wanjian.networkhospitalmanager.adapter.OperationImageGridAdapter;
import com.net.wanjian.networkhospitalmanager.adapter.ShowLabOperationAdapter;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.SearchDeviceDetailResult;
import com.net.wanjian.networkhospitalmanager.net.HttpUtil;
import com.net.wanjian.networkhospitalmanager.netstatus.NetUtils;
import com.net.wanjian.networkhospitalmanager.utils.PicassoUtil;
import com.net.wanjian.networkhospitalmanager.utils.SharedXmlUtil;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ShowLabOperationActivity extends BaseActivity {
    public static final String LAB_RESERVE_MEMBER_OPERATION_KEY = "com.net.wanjian.activity.lab_reserve_member_operation_key";

    @BindView(R.id.top_back_layout)
    LinearLayout topBackLayout;
    @BindView(R.id.top_title_tv)
    TextView topTitleTv;
    @BindView(R.id.submit_lab_device_iv)
    ImageView submitLabDeviceIv;
    @BindView(R.id.submit_lab_device_desc_tv)
    TextView submitLabDeviceDescTv;
    @BindView(R.id.submit_lab_device_sums_et)
    TextView submitLabDeviceSumsEt;
    @BindView(R.id.submit_lab_image_recycler)
    RecyclerView submitLabImageRecycler;
    private SearchDeviceDetailResult.DataBean.LabReserveMemberOperationInfoBean infoBean;
    private ArrayList<String> imageUrls; //图片的id集合
    private ShowLabOperationAdapter operationAdapter;

    @Override
    protected void initData() {
        topBackLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShowLabOperationActivity.this.finish();
            }
        });
        Bundle bundle = getIntent().getExtras();
        infoBean = (SearchDeviceDetailResult.DataBean.LabReserveMemberOperationInfoBean) bundle.getSerializable(LAB_RESERVE_MEMBER_OPERATION_KEY);

            setUI();

    }

    private void setUI() {
//        topTitleTv.setText(URLDecoderUtil.getDecoder(infoBean.getDeviceName()));
        topTitleTv.setText("设备");
            submitLabDeviceDescTv.setText(URLDecoderUtil.getDecoder(infoBean.getDeviceRemark()));
            submitLabDeviceSumsEt.setText(URLDecoderUtil.getDecoder(infoBean.getLabReserveMemberOperationRemark()));
            PicassoUtil.loadImage(this, HttpUtil.getDevicePhoto(URLDecoderUtil.getDecoder(infoBean.getDeviceID()), SharedXmlUtil.getInstance().getHospitalId()), R.mipmap.user, submitLabDeviceIv);


        //加载操作图片并显示
        //封装url集合
        imageUrls = (ArrayList<String>) infoBean.getLabReserveMemberOperationImageIDList();
        submitLabImageRecycler.setLayoutManager(new GridLayoutManager(this, 4));
        operationAdapter = new ShowLabOperationAdapter(this, imageUrls);
        submitLabImageRecycler.setAdapter(operationAdapter);

        operationAdapter.setOnItemClickListener(new RecyclerBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int pos) {
                Bundle bundle = new Bundle();
                bundle.putString("ImageBig",imageUrls.get(pos));
                openActivity(PhotoViewActivity.class,bundle);
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_show_lab_operation;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

}
